package priv.conceit.sc.hoxton.file.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
import priv.conceit.sc.hoxton.common.util.FileSuffixUtil;

import java.util.List;

/**
 * sc-hoxton
 *
 * @author Conceit
 * @since 1.0.0, 2020/5/11
 */
@Data
@ConfigurationProperties(FileProperties.PREFIX)
@RefreshScope
@Component
public class FileProperties {

	public static final String PREFIX="file";

	private FileSourceProperties source;

	private Preview preview;
	private Download download;
	private String convertDir;
	private String tempDir;
	/**
	 * 清理convertDir tempDir 文件间隔（天）
	 */
	private Integer cleanInterval=30;
	private Upload upload;
	private ShortCode shortCode;



	@Data
	public static class Preview{
		private Boolean ignoreCase=true;
		private List<String> pictureSuffixs = FileSuffixUtil.DEFAULT_PREVIEW_PICTURE_SUFFIXS;
		private List<String> videoSuffixs=FileSuffixUtil.DEFAULT_PREVIEW_VIDEO_SUFFIXS;
		private List<String> textSuffixs=FileSuffixUtil.DEFAULT_PREVIEW_TEXT_SUFFIXS;
		private List<String> musicSuffixs=FileSuffixUtil.DEFAULT_PREVIEW_MUSIC_SUFFIXS;
		private List<String> compressSuffixs=FileSuffixUtil.DEFAULT_PREVIEW_COMPRESS_SUFFIXS;
		private List<String> officeSuffixs=FileSuffixUtil.DEFAULT_PREVIEW_OFFICE_SUFFIXS;
		private List<String> pdfSuffixs=FileSuffixUtil.DEFAULT_PREVIEW_PDF_SUFFIXS;
		private List<String> cadSuffixs=FileSuffixUtil.DEFAULT_PREVIEW_CAD_SUFFIXS;

		public List<String> merge=FileSuffixUtil.merge(pictureSuffixs,videoSuffixs,textSuffixs,
				musicSuffixs,compressSuffixs,officeSuffixs,pdfSuffixs,cadSuffixs
		);
	}

	@Data
	public static class Download{
		private String fileNameEncoder="UTF-8";
	}

	@Data
	public  static class Upload{
		private Boolean ignoreCase=true;
		private List<String> pictureSuffixs = FileSuffixUtil.DEFAULT_UPLOAD_PICTURE_SUFFIXS;
		private List<String> videoSuffixs=FileSuffixUtil.DEFAULT_UPLOAD_VIDEO_SUFFIXS;
		private List<String> textSuffixs=FileSuffixUtil.DEFAULT_UPLOAD_TEXT_SUFFIXS;
		private List<String> musicSuffixs=FileSuffixUtil.DEFAULT_UPLOAD_MUSIC_SUFFIXS;
		private List<String> compressSuffixs=FileSuffixUtil.DEFAULT_UPLOAD_COMPRESS_SUFFIXS;
		private List<String> officeSuffixs=FileSuffixUtil.DEFAULT_UPLOAD_OFFICE_SUFFIXS;
		private List<String> pdfSuffixs=FileSuffixUtil.DEFAULT_UPLOAD_PDF_SUFFIXS;
		private List<String> cadSuffixs=FileSuffixUtil.DEFAULT_UPLOAD_CAD_SUFFIXS;
		private List<String> otherSuffixs=FileSuffixUtil.DEFAULT_UPLOAD_OTHER_SUFFIXS;

		public List<String> merge=FileSuffixUtil.merge(pictureSuffixs,videoSuffixs,textSuffixs,
				musicSuffixs,compressSuffixs,officeSuffixs,pdfSuffixs,cadSuffixs,otherSuffixs
		);

		private SavedName savedName;
		private SavedMidPath savedMidPath;

		@Data
		public  static class SavedName{
			private String signSeparator="-";
		}

		@Data
		public  static class SavedMidPath{
			private String firstFormat="yyyyMM";
			private String secondFormat="yyyyMMdd";
		}



	}
	@Data
	public static class ShortCode{
		private Integer randomLength=5;
	}

}
